home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-22 | 11.6 KB | 325 lines | [TEXT/MPS ] |
- //-----------------------------------------------------------------------------
- // SLCyPart.cpp
- // Implementation of FW_OCyberPartExtension.
- // Redirects all methods into C callbacks provided by the client.
- //
- // Copyright (c) 1995 - 1996 by Apple Computer, Inc., all rights reserved.
- //-----------------------------------------------------------------------------
-
- #define ODF_FW_OCyberPartExtension_Class_Source
- #include <SLCyPart.xih>
-
- #include <MemMgr.h>
-
- //-----------------------------------------------------------------------------
- // Since we have a SOM interface, we have to make sure we don't try to
- // throw any C++ exceptions out of here; we need to catch them and convert
- // them into SOM exceptions.
- // Note that while the C callbacks *must* not throw exception and will set
- // ev->_major, all other method calls, including the _parent_ macros, will
- // invoke SOMCHKEXCEPT and therefore may throw exceptions.
- //-----------------------------------------------------------------------------
-
- static const char FW_kInvalidException[] = "Unknown Exception!";
-
- #define BEGIN_SOM_SAFETY \
- FW_TRY \
- {
-
- #define END_SOM_SAFETY \
- } \
- FW_CATCH_BEGIN \
- FW_CATCH_REFERENCE(FW_XException, exception)\
- { \
- FW_SetException(ev, exception);\
- } \
- FW_CATCH_EVERYTHING() \
- { \
- FW_DEBUG_MESSAGE(FW_kInvalidException);\
- FW_SetEvError(ev, kODErrUndefined);\
- } \
- FW_CATCH_END
-
- //-----------------------------------------------------------------------------
- // We should not do anything if our base part has been removed (IsValid).
- // Also make sure we have a callback struct and callback.
- //-----------------------------------------------------------------------------
-
- #define SAFECALL(RESULT,METHOD,PARAMETERS) \
- if (somSelf->IsValid(ev) \
- && somThis->fCallbacks \
- && somThis->fCallbacks->METHOD) \
- (RESULT (somThis->fCallbacks->METHOD) PARAMETERS, SOMCHKEXCEPT)
-
- /*-----------------------------------------------------------------------------
- SOM Subclass of CyberPartExtension
-
- These methods generally call C methods which have been exported from a
- client. These C methods must not throw C++ exceptions. Most of these
- methods here don't call C++ methods or somSelf methods and so do not
- need to guard against exceptions being thrown via SOMCHKEXCEPT.
- -----------------------------------------------------------------------------*/
-
- SOM_Scope void SOMLINK SLCyPart__Release (ODF_FW_OCyberPartExtension *somSelf, Environment *ev)
- {
- BEGIN_SOM_SAFETY
-
- ODBoolean isOwned = somSelf->IsValid (ev);
- ODF_FW_OCyberPartExtension_parent_CyberPartExtension_Release(somSelf,ev);
-
- if (!isOwned && somSelf->GetRefCount(ev) == 0)
- delete somSelf;
-
- END_SOM_SAFETY
- }
-
- SOM_Scope void SOMLINK
- SLCyPart__OpenCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, CyberItem* item, ODPart* openerPart, ParameterSet* openParams)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- BEGIN_SOM_SAFETY
-
- // The base class implements the default behavior, which is to call
- // somSelf->SetCyberItem(item), and then to either tell the openerPart
- // (if it is not kODNULL) to open the associated base part, or to tell
- // the base part to open itself.
- // Developers may call inherited.
-
- // mlanett 4/18/96 In order to make it possible for developer to call inherited, the
- // call to ODF_FW_OCyberPartExtension_parent_CyberPartExtension_OpenCyberItem has been
- // moved to DefaultOpenCyberItem. FW_MCyberPart calls this by default. Developers
- // can override, and by calling inherited from C++, will get the actual inherited SOM
- // functionality. See FW_MCyberPart::HandleOpenCyberItem.
- ODBoolean callInherited = false;
-
- SAFECALL(,openCyberItem,(ev, somThis->fCallbacks, item, openerPart, openParams));
-
- if (callInherited)
- ODF_FW_OCyberPartExtension_parent_CyberPartExtension_OpenCyberItem(somSelf,ev,item,openerPart,openParams);
-
- END_SOM_SAFETY
- }
-
- SOM_Scope void SOMLINK
- SLCyPart__SetCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, CyberItem* item, ParameterSet* openParams)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
-
- // This method is called to notify the extension that it is now
- // responsible for displaying a new CyberItem. Developers will
- // typically override this method to notify the associated part.
- // Base class releases the old CyberItem (if any) and acquires the new
- // CyberItem. Subsequent calls to GetCyberItem will return this item.
-
- ODF_FW_OCyberPartExtension_parent_CyberPartExtension_SetCyberItem(somSelf,ev,item,openParams);
-
- SAFECALL(,setCyberItem,(ev, somThis->fCallbacks, item, openParams));
- }
-
- SOM_Scope ODBoolean SOMLINK
- SLCyPart__CanShowCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- CyberItem* item)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
-
- // Returns kODTrue if this CyberPart is displaying the specified item.
- // Base class checks whether the item is equal to the value of
- // GetCyberItem(). Note that in some cases developers may wish to use a
- // less stringent test. For example, a web browser may return kODTrue
- // if the item that is passed is a link to a location on that same page
- // that it is displaying. In this case the URL of the item passed in is
- // not the same as the URL of current page, but it is contained in that
- // window.
-
- // This is like an object equality test. x == y is true if x and y
- // are the same object, or if they are similar objects. So, even if the
- // base class returns false (not equal) we still need to test for
- // similarity. Obviously if it returns true then we don't need to
- // test further.
-
- // I think this method is rather badly named.
-
- ODBoolean isSimilar = ODF_FW_OCyberPartExtension_parent_CyberPartExtension_CanShowCyberItem(somSelf,ev,item);
- if (!isSimilar)
- SAFECALL(isSimilar=,canShowCyberItem,(ev, somThis->fCallbacks, item));
-
- return isSimilar;
- }
-
- SOM_Scope void SOMLINK
- SLCyPart__ShowCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, CyberItem* item)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
-
- // Tells the part to display the given CyberItem. This differs from
- // SetCyberItem in that the extension has already indicated (through
- // CanShowCyberItem or GetCyberItemWindow) that it is already
- // displaying a cyberitem equal to (or, for example, on the same page
- // as) the item parameter.
- // Developers must not call inherited.
-
- SAFECALL(,showCyberItem,(ev, somThis->fCallbacks, item));
- }
-
- SOM_Scope ODWindow* SOMLINK
- SLCyPart__GetCyberItemWindow (ODF_FW_OCyberPartExtension *somSelf, Environment* ev, CyberItem* item)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- ODWindow* window = kODNULL;
- BEGIN_SOM_SAFETY
-
- // Returns the ODWindow (if any) in which this CyberPart is displaying
- // the specified item. This is useful e.g. when the client wants to
- // bring an existing window to the front rather than opening a new
- // window. GetCyberItemWindow should use the same algorithm as in
- // CanShowCyberItem method to determine whether an item is displayed in
- // a window.
-
- ODBoolean isShowingSimilar;
- isShowingSimilar = somSelf->CanShowCyberItem (ev, item);
-
- if (isShowingSimilar)
- SAFECALL(window=,getCyberItemWindow,(ev, somThis->fCallbacks, item));
-
- END_SOM_SAFETY
- return window;
- }
-
- SOM_Scope ODBoolean SOMLINK
- SLCyPart__IsCyberItemSelected(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, ODFrame* frame)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- ODBoolean isAnySelected = false;
- BEGIN_SOM_SAFETY
-
- SAFECALL(isAnySelected=,isCyberItemSelected,(ev, somThis->fCallbacks, frame));
-
- END_SOM_SAFETY
- return isAnySelected;
- }
-
- SOM_Scope void SOMLINK
- SLCyPart__AcquireSelectedCyberItems(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, ODFrame* frame, CyberItemList* cyberItems)
- {
- // XXX should change this to pass an STL list?
- // Note: If I do it has to be exception-safe.
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- BEGIN_SOM_SAFETY
-
- SAFECALL(,acquireSelectedCyberItems,(ev, somThis->fCallbacks, frame, cyberItems));
-
- END_SOM_SAFETY
- }
-
- SOM_Scope ODBoolean SOMLINK
- SLCyPart__IsURLSelected(ODF_FW_OCyberPartExtension *somSelf, Environment* ev, ODFrame* frame)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- ODBoolean isSelected = FALSE;
- BEGIN_SOM_SAFETY
-
- SAFECALL(isSelected=,isURLSelected,(ev, somThis->fCallbacks, frame));
-
- END_SOM_SAFETY
- return isSelected;
- }
-
- SOM_Scope char* SOMLINK
- SLCyPart__GetSelectedURL(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- ODFrame* frame)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- char* urld = kODNULL;
- BEGIN_SOM_SAFETY
-
- FW_CString surl;
- SAFECALL(,getSelectedURL,(ev, somThis->fCallbacks, frame, surl));
-
- // Note: this code has been arranged so it does not throw any C++ exceptions.
- FW_ByteCount size = surl.GetByteLength();
- if (size) {
- urld = (char*) ::MMAllocate (size + 1);
- if (urld) {
- const char* privates = surl.RevealBuffer();
- memcpy (urld, privates, size);
- urld[size] = 0;
- }
- else
- FW_SetException (ev, kODErrOutOfMemory);
- }
-
- END_SOM_SAFETY
-
- return urld;
- }
-
- SOM_Scope ODBoolean SOMLINK
- SLCyPart__HandleCommand(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- long commandSuite,
- long commandID,
- ODFrame* frame,
- void* commandData)
- {
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- ODBoolean wasHandled = false;
- BEGIN_SOM_SAFETY
-
- // Intended as an extensibility mechanism for Cyber parts where clients
- // can send commands to the part/extension. The function result
- // indicates whether or not the command was handled.
- // Cyberdog defines some commands in Cyberdog.h. The commandCreator
- // associated with Cyberdogs commands is kCyberdogCreator.
- // Developers may call inherited.
-
- // mlanett 4/18/96 see comment for OpenCyberItem. Removed call to inherited. See FW_MCyberPart::HandleCyberCommand.
- ODBoolean callInherited = false;
-
- SAFECALL(wasHandled=,handleCommand,(ev, somThis->fCallbacks, commandSuite, commandID, frame, commandData));
- if (callInherited)
- wasHandled |= ODF_FW_OCyberPartExtension_parent_CyberPartExtension_HandleCommand (somSelf,ev,commandSuite,commandID,frame,commandData);
-
- END_SOM_SAFETY
- return wasHandled;
- }
-
- SOM_Scope void SOMLINK
- SLCyPart__SetCallbacks(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- FW_HCyberPartInterfaceCallbacks callbacks)
- {
- // Note: No exception handling here.
- FW_UNUSED(ev);
-
- ODF_FW_OCyberPartExtensionData *somThis = ODF_FW_OCyberPartExtensionGetData(somSelf);
- somThis->fCallbacks = callbacks;
- }
-
- SOM_Scope void SOMLINK SLCyPart__DefaultOpenCyberItem(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- CyberItem* item,
- ODPart* openerPart,
- ParameterSet* openParams)
- {
- BEGIN_SOM_SAFETY
-
- // This method enabled us to call "inherited" OpenCyberItem from the C++ class.
- ODF_FW_OCyberPartExtension_parent_CyberPartExtension_OpenCyberItem(somSelf,ev,item,openerPart,openParams);
-
- END_SOM_SAFETY
- }
-
- SOM_Scope ODBoolean SOMLINK SLCyPart__DefaultHandleCommand(ODF_FW_OCyberPartExtension *somSelf, Environment *ev,
- long commandCreator,
- long commandID,
- ODFrame* frame,
- void* commandData)
- {
- ODBoolean handled = FALSE;
- BEGIN_SOM_SAFETY
-
- // This method enabled us to call "inherited" HandleCommand from the C++ class.
- handled = ODF_FW_OCyberPartExtension_parent_CyberPartExtension_HandleCommand (somSelf,ev,commandCreator,commandID,frame,commandData);
-
- END_SOM_SAFETY
- return handled;
- }
-
-